package gui.commands;

import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

import common.Result;

public class MultipleCommands implements Command
{
  List<Command> commands = new ArrayList<Command>();

  @Override
  public Result reverse()
  {
    ListIterator<Command> li = commands.listIterator(commands.size());
    while (li.hasPrevious())
    {
      Command c = li.previous();
      Result r = c.reverse();

      assert r.getStatus() : "Command couldn't be reversed.";
    }

    return new Result(true);
  }

  @Override
  public Result execute()
  {
    for (Command c : commands)
    {
      Result r = c.execute();
      assert r.getStatus() : "Command couldn't be executed.";
    }

    return new Result(true);
  }

  public void addCommand(Command c)
  {
    commands.add(c);
  }

}
